<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/templates/template.xhtml">
	<ui:define name="pageTitle">Equipes</ui:define>
	<ui:define name="pageHeader">Cadastro de Equipes</ui:define>
	<ui:define name="body">

		<h:form id="edicao">

			<h:inputHidden value="#{equipeBean.equipeSelecionada.id}" />

			<h:panelGrid columns="2">

				<h:outputText value="Nome" />
				<h:inputText value="#{equipeBean.equipeSelecionada.nome}" />

				<h:outputText value="Status do Treinamento" />
				<h:inputText
					value="#{equipeBean.equipeSelecionada.statusTreinamento}" />

				<h:outputText value="Ativa" />
				<h:selectBooleanCheckbox
					value="#{equipeBean.equipeSelecionada.ativa}" />

				<h:outputText value="Observações" />
				<h:inputTextarea value="#{equipeBean.equipeSelecionada.obs}" />

				<h:selectOneMenu value="#{equipeBean.equipeSelecionada.esporte}">
					<f:selectItem itemLabel="nenhum" />
					<f:selectItems value="#{equipeBean.esportesSelectList}"/>
					<f:converter converterId="esporteConverter"/>
				</h:selectOneMenu>

			</h:panelGrid>

			<p />
				<h:commandButton action="#{equipeBean.novo}" value="Nova Equipe" style=" width : 112px;" />
				<h:commandButton action="#{equipeBean.salvar}" value="Salvar" 	 style=" width : 112px;" />
				<h:messages />
			<p />

		</h:form>


		<h:form id="lista">

			<h:dataTable value="#{equipeBean.lista}" var="equipeListada"
				border="1" rendered="#{not empty equipeBean.lista}">

				<h:column>
					<f:facet name="header">Nome</f:facet>
					#{equipeListada.nome}					
				</h:column>

				<h:column>
					<f:facet name="header">Status Treinamento</f:facet>
					#{equipeListada.statusTreinamento}
				</h:column>
				
				<h:column>
					<f:facet name="header">Ativa</f:facet>
					<center>
					<h:graphicImage value="/resources/images/checkmark-16.png" rendered="#{equipeListada.ativa}" />
					</center>
				</h:column>

				<h:column>
					<f:facet name="header">Atletas</f:facet>
					#{equipeListada.atletas.size()}
				</h:column>

				<h:column>
					<f:facet name="header">Obs</f:facet>
					#{equipeListada.obs}
				</h:column>

				<h:column>
					<f:facet name="header">Esporte</f:facet>
					#{equipeListada.esporte.nome}
				</h:column>

				<h:column>
				
					<f:facet name="header">Ações</f:facet>
					
					<h:commandLink action="#{equipeBean.excluir()}" onclick="if(!confirm('Deseja excluir a equipe #{equipeListada.nome}?')) return false;">
						<h:graphicImage value="/resources/images/trash-icon24px.png" />
						<f:setPropertyActionListener target="#{equipeBean.equipeSelecionada}" value="#{equipeListada}" />
					</h:commandLink>
					
					<h:commandLink>
						<h:graphicImage value="/resources/images/wrench-icon-24px.png" />
						<f:setPropertyActionListener target="#{equipeBean.equipeSelecionada}" value="#{equipeListada}" />
					</h:commandLink>
					
				</h:column>

			</h:dataTable>

		</h:form>

	</ui:define>
</ui:composition>

</html>